package br.com.montadora.abc.dao;

import br.com.montadora.abc.util.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Aurelio
 */
public class DAOFactory {

	private final Session session; 	
	private Transaction transaction;
	
	
	public DAOFactory() {
		session = HibernateUtil.getSession();
	}
	

	public void beginTransaction(){
		if(hasTransaction()){
			stopTransaction();
		}
		this.transaction = this.session.beginTransaction();
	}
	
	public void commit(){
		this.transaction.commit();
	}
	
	public boolean hasTransaction(){
		return this.transaction != null;
	}
	
	public void rollback(){
		this.transaction.rollback();
		this.transaction = null;
	}
	
	public void stopTransaction(){
		this.transaction = null;
	}
	
	public void close(){
		this.session.close();
	}
	
	public void clear(){
		this.session.clear();
	}
	
//	public DepartamentoDao getDepartamentoDao() {
//		return new DepartamentoDao(this.session);
//	}
	
}

